/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * CellGridPanel.java
 *
 * Created on Feb 5, 2012, 10:56:26 PM
 */
package ui.components;

import entities.User;
import java.awt.Color;

/**
 *
 * @author viev
 */
public class CellGridPanel extends javax.swing.JPanel {

    /** Creates new form CellGridPanel */
    public CellGridPanel(ShowEmployeeGridPanel parentPanel, User user) {
        this.parentPanel = parentPanel;
        this.user = user;
        initComponents();
        includeModel();
    }

    private void includeModel() {
        if (user != null) {
            String[] roles = {"Administractor", "Department Head", "Employee"};
            String[][] levels = {{"Head", "Employee"},
                {"Head", "Immediate Head", "Next Immediate Head", "Junior Head "},
                {"Doctor", "Staff"}};
            lbName.setText(user.getName());
            lbDep.setText(user.getDepartmentName());
            lbRole.setText(roles[user.getRole() - 2]);
            lbLevel.setText(levels[user.getRole() - 2][user.getLevel() - 1]);
        }
    }
    
    public void setLock(boolean lock) {
        this.lock = lock;
        if(lock) {
            this.setBackground(new Color(0, 153, 153));
        } else {
            this.setBackground(new Color(0, 51, 51));
        }
    }

    public void setSelectedUser() {
        parentPanel.setSelectedUser(user);
        parentPanel.setSelectedItem(this);
        this.setBackground(new Color(0, 153, 153));
        lock = true;
    }
    
    private void mouseEnteredAction() {
        if(!lock) {
            this.setBackground(new Color(0, 153, 153));
        }
    }
    
    private void mouseExitedAction() {
        if(!lock) {
            this.setBackground(new Color(0, 51, 51));
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    private boolean lock;
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        lbPic = new javax.swing.JLabel();
        lbName = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        lbDep = new javax.swing.JLabel();
        lbRole = new javax.swing.JLabel();
        lbLevel = new javax.swing.JLabel();

        setBackground(new java.awt.Color(0, 51, 51));
        setBorder(javax.swing.BorderFactory.createMatteBorder(1, 1, 1, 1, new java.awt.Color(255, 255, 204)));
        addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                formMouseClicked(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                formMouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                formMouseExited(evt);
            }
        });

        jPanel1.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
        jPanel1.setLayout(new java.awt.BorderLayout());
        jPanel1.add(lbPic, java.awt.BorderLayout.CENTER);

        lbName.setBackground(new java.awt.Color(204, 204, 204));
        lbName.setFont(new java.awt.Font("Tahoma", 1, 12));
        lbName.setForeground(new java.awt.Color(255, 255, 204));
        lbName.setText("Name");

        jLabel2.setForeground(new java.awt.Color(255, 255, 204));
        jLabel2.setText("Department:");

        jLabel3.setForeground(new java.awt.Color(255, 255, 204));
        jLabel3.setText("Role:");

        jLabel4.setForeground(new java.awt.Color(255, 255, 204));
        jLabel4.setText("Level:");

        lbDep.setFont(new java.awt.Font("Tahoma", 1, 11));
        lbDep.setForeground(new java.awt.Color(255, 255, 204));
        lbDep.setText("value");

        lbRole.setFont(new java.awt.Font("Tahoma", 1, 11));
        lbRole.setForeground(new java.awt.Color(255, 255, 204));
        lbRole.setText("value");

        lbLevel.setFont(new java.awt.Font("Tahoma", 1, 11));
        lbLevel.setForeground(new java.awt.Color(255, 255, 204));
        lbLevel.setText("value");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 103, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(63, 63, 63)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lbName)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel2)
                            .addComponent(jLabel3)
                            .addComponent(jLabel4))
                        .addGap(31, 31, 31)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lbLevel)
                            .addComponent(lbRole)
                            .addComponent(lbDep))))
                .addContainerGap(162, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(lbName)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel2)
                            .addComponent(lbDep))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel3)
                            .addComponent(lbRole))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel4)
                            .addComponent(lbLevel)))
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 113, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

private void formMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_formMouseClicked
    setSelectedUser();
}//GEN-LAST:event_formMouseClicked

private void formMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_formMouseEntered
    mouseEnteredAction();
}//GEN-LAST:event_formMouseEntered

private void formMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_formMouseExited
    mouseExitedAction();
}//GEN-LAST:event_formMouseExited
    private ShowEmployeeGridPanel parentPanel;
    private User user;
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JLabel lbDep;
    private javax.swing.JLabel lbLevel;
    private javax.swing.JLabel lbName;
    private javax.swing.JLabel lbPic;
    private javax.swing.JLabel lbRole;
    // End of variables declaration//GEN-END:variables
}
